package com.bachelor.community.controller;

import cn.hutool.core.util.StrUtil;
import com.bachelor.community.model.dto.UserDTO;
import com.bachelor.community.service.intf.UserService;
import com.bachelor.community.utils.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Resource
    private UserService userService;

    @PostMapping
    public Result login(@RequestBody UserDTO userDTO) {
        String account = userDTO.getAccount();
        String password = userDTO.getPassword();
        if (StrUtil.isBlank(account) || StrUtil.isBlank(password)) {
            return Result.fail("401", "用户名或密码不能为空");
        } else {
            return Result.succeed("200", userService.login(userDTO));
        }
    }
}
